import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xuance/constant.dart';
import 'package:xuance/widget/EmptyWidget.dart';
import 'package:xuance/widget/PolicyWidget.dart';

import 'me_logic.dart';

class MePage extends StatelessWidget {
  const MePage({super.key});

  @override
  Widget build(BuildContext context) {
    final logic = Get.find<MeLogic>();
    final state = logic.state;
    return Scaffold(
        backgroundColor: bgColor,
        body: SafeArea(
            child: Column(children: [
          Stack(
            children: [
              Padding(
                padding: const EdgeInsets.symmetric(vertical: 20),
                child: Center(
                  child: Obx(() {
                    return Text("欢迎登录,${logic.username.value}",
                        style: const TextStyle(color: Colors.white));
                  }),
                ),
              ),
              Positioned(
                  right: 10,
                  bottom: 0,
                  top: 0,
                  child: GestureDetector(
                    onTap: logic.logout,
                    child: const Padding(
                      padding: EdgeInsets.all(10),
                      child: Icon(
                        Icons.exit_to_app_outlined,
                        color: Colors.white,
                      ),
                    ),
                  ))
            ],
          ),
          Expanded(
              child: Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 15),
                  child: Column(children: [
                    Expanded(
                      child: Obx(() {
                        if (state.list.isEmpty) {
                          return const EmptyWidget();
                        }
                        return ListView.builder(
                            itemCount: state.list.length,
                            itemBuilder: (BuildContext context, int index) {
                              var bean = state.list[index];
                              return Container(
                                padding: const EdgeInsets.all(10),
                                decoration: BoxDecoration(
                                    color: index % 2 == 0
                                        ? const Color(0xff233F48)
                                        : Colors.transparent,
                                    borderRadius: br5),
                                child: Text(
                                  "${bean.loginTime},登录IP:${bean.ip}",
                                  style: const TextStyle(color: Colors.white),
                                ),
                              );
                            });
                      }),
                    ),
                    Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          GestureDetector(
                              onTap: logic.lastPage,
                              child: const Padding(
                                  padding: EdgeInsets.all(8.0),
                                  child: Text("上一页",
                                      style: TextStyle(
                                          color: Color(0xff9EA1A6))))),
                          Obx(() {
                            return Text(
                                "第${logic.page.value}页,共${state.totalPage.value}页",
                                style:
                                    const TextStyle(color: Color(0xff9EA1A6)));
                          }),
                          GestureDetector(
                              onTap: logic.nextPage,
                              child: Padding(
                                  padding: const EdgeInsets.all(8.0),
                                  child: Text("下一页",
                                      style: TextStyle(color: c_green))))
                        ])
                  ]))),
          const PolicyWidget(
            enable: true,
            isCheck: false,
          ),
          const SizedBox(height: 10)
        ])));
  }
}
